package com.tingyuge.thinking.spring.configuration.bean.factory;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * 默认 {@link UserFactory}
 * @author xiaodao
 * @version 1.0
 * @date 2021/6/27
 */
public class DefaultUserFactory implements UserFactory , InitializingBean, DisposableBean {

    //1. 基于@postConstruct 注解

    @PostConstruct
    public void  init(){
        System.out.println(" @PostConstruct init bean 初始化");

    }

    public void  initUserFactory(){
        System.out.println("自定义初始化方法: initUserFactory  bean 初始化");

    }

    //AbstractBeanDefinition
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("InitializingBean#afterPropertiesSet  bean 初始化");
    }


    @PreDestroy
    public void  preDestroy(){
        System.out.println("DefaultUserFactory.preDestroy   @PreDestroy 销毁中");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("DefaultUserFactory.destroy userFactory 销毁中 ");
    }

    public void doDestroy(){
        System.out.println("DefaultUserFactory.doDestroy  自定义销毁中...");
    }

    @Override
    protected void finalize() throws Throwable {
        System.out.println("当前对象 userFactory正在被回收....");
    }
}
